<template>
  <div class="swiper">
    <swiper :options="swiperOption" v-if="imageList">
      <swiper-slide v-for="(item,index) in imgList" :key="index">
        <router-link :to="item.link" v-if="item.link">
          <img :src="item.img" alt="">
        </router-link>
        <img :src="item.img" v-else alt="">
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'

export default {
  props: ['imgList'],
  data() {
    return {
      imageList: [],
      swiperOption: {
        pagination: {
          el: '.swiper-pagination',
          type: 'fraction'
        },
        effect: 'fade',
        autoplay: {
          disableOnInteraction: false
        },
        loop: true
      }
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  created() {
    this.initImg()
    this.showImg()
  },
  methods: {
    showImg() {
      this.imageList = this.imgList
    },
    initImg() {
      this.imageList = []
    }
  },
  watch: {
    imageList: 'showImg'
  }
}
</script>

<style lang="scss" scoped>
@import './../common/scss/common.scss';
.swiper {
  img {
    width: 100%;
    max-width: 100%;
  }
  .swiper-pagination {
    @include font(12px,$white);
    &:after {
      display: inline-block;
      content: '';
      @include allCPostion(50%,49.999%);
      z-index: -1;
      @include size(40px, 20px);
      border-radius: 10px;
      background: rgba($black0, 0.3);
    }
    &.swiper-pagination-fraction {
      bottom: 15px;
    }
  }
}
</style>

